home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / mc51bugs / q32244 < prev    next >
Text File  |  1988-08-24  |  2KB  |  64 lines

  1. Q32244 Huge Arithmetic Not Being Applied to Huge Pointer
  2. C Compiler
  3. 5.10 | 5.10
  4. OS/2 | MS-DOS
  5.  
  6. Summary:
  7.    In small model, huge-pointer arithmetic is not being applied to a
  8. binary expression involving a huge pointer and an integer.
  9.    Given a pointer declared as follows:
  10.  
  11.     char huge * ptr;
  12.  
  13. the following statements should be equivalent:
  14.  
  15.     ptr = ptr + 128000;               /* this fails */
  16.     ptr = (char huge *) ptr + 128000; /* this works only if */
  17.                                       /* compiled with -Od */
  18.     ptr = ptr + foo();                /* this works */
  19.                                       /* foo() returns 128000 */
  20.  
  21.    The first statement incorrectly adds together only the offsets,
  22. whereas the second and third statements add both segments and offsets,
  23. as specified by the huge keyword.
  24.    The workarounds to this problem are demonstrated in the example:
  25. either use an explicit typecast and disable optimization with the
  26. compiler option /Od (or -Od), or make a function call to return the
  27. value.
  28.    This problem should be corrected in the next release of C.
  29.  
  30. More Information:
  31.    The following program demonstrates the problem:
  32.  
  33. #include <stdio.h>
  34.  
  35. void main(void);
  36. long foo(void);
  37.  
  38. char huge * ptr;
  39.  
  40. void main(void)
  41. {
  42.     printf("ptr is 0.\n");
  43.     ptr = 0;
  44.     ptr = ptr + 128000;
  45.     printf("ptr + 128000 = %lp...Wrong!\n", ptr);
  46.  
  47.     ptr = 0;
  48.     ptr = (char huge *) ptr + 128000;
  49.     printf("(char huge *) ptr +128000 = %lp...Correct.\n", ptr);
  50.  
  51.     ptr = 0;
  52.     ptr = ptr + foo();
  53.     printf("ptr + foo() = %lp...Also correct.\n", ptr);
  54. }
  55.  
  56. long foo(void)
  57. {
  58.     return 128000;
  59. }
  60.  
  61.  
  62. Keywords:  buglist5.10
  63. Updated  88/08/25 05:19
  64.